<template>
  <a-modal
    :title="title"
    width="50%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.deptname" placeholder="请输入单位名称"/>
            </a-form-item>
            <a-form-item label="单位岗位数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number
                placeholder="请输入单位岗位数量"
                v-model="infoData.companyNum"
                :min="0"
                :max="3"
                :step="1"
                :style="{width:'100%'}"/>
            </a-form-item>
            <!-- <a-form-item label="单位岗位可选数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input-number placeholder="请输入单位岗位可选数量" v-model="infoData.trueNum" :min="0" :max="3" :step="1" :style="{width:'100%'}"/>
              </a-form-item> -->
            <a-form-item label="院校名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.schoolname" placeholder="请输入院校名称"/>
            </a-form-item>
            <!-- <a-form-item label="专业代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.majorcode" placeholder="请输入专业代码"/>
            </a-form-item> -->
            <a-form-item label="专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <a-input v-model="infoData.majorname" placeholder="请输入专业名称"/> -->
              <a-select v-model="infoData.majorcode" placeholder="请选择" default-value="0">
                <a-select-option  v-for="(obj, index) in selectData['001']" :key="index" :value="obj.code">{{obj.name}}</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="培养目标" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.target" placeholder="请输入培养目标"/>
            </a-form-item>
            <a-form-item label="对象" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <a-input v-model="infoData.object" placeholder="请输入对象"/> -->
              <a-select default-value="青年学生" v-model="infoData.object" placeholder="请选择对象">
                <a-select-option value="青年学生"> 青年学生 </a-select-option>
                <a-select-option value="士兵学员"> 士兵学员 </a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="学制" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <a-input v-model="infoData.schlength" placeholder="请输入学制"/> -->
              <a-select default-value="一年" v-model="infoData.schlength" placeholder="请选择学制">
                <a-select-option value="一年"> 一年 </a-select-option>
                <a-select-option value="四年"> 四年 </a-select-option>
                <a-select-option value="五年"> 五年 </a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <a-input v-model="infoData.edu" placeholder="请输入学历"/> -->
              <a-select default-value="本科" v-model="infoData.edu" placeholder="请选择学历">
                <a-select-option value="本科"> 本科 </a-select-option>
                <a-select-option value="硕士"> 硕士 </a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <a-input v-model="infoData.gender" placeholder="请输入性别"/> -->
              <a-select default-value="男" v-model="infoData.gender" placeholder="请选择性别">
                <a-select-option value="男"> 男 </a-select-option>
                <a-select-option value="女"> 女 </a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="是否艰苦地区" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <a-input v-model="infoData.hardFlg" placeholder="请输入是否艰苦地区"/> -->
              <a-select default-value="是" v-model="infoData.hardFlg" placeholder="请选择是否艰苦地区">
                <a-select-option value="是"> 是 </a-select-option>
                <a-select-option value="否"> 否 </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <template slot="footer">
      <a-button key="back" type="primary" @click="handleOk">
        保存并关闭
      </a-button>
    </template>
  </a-modal>
</template>

<script>
import { getUrl,postAxiosUrl } from '@/api/manage'
import moment from 'moment'
export default {
  components:{},
  data () {
    return {
      labelCol: { lg: { span: 5 }, sm: { span: 5 } },
      wrapperCol: { lg: { span: 19 }, sm: { span: 19 } },
      form: this.$form.createForm(this),
      title:'',
      visible: false,
      confirmLoading: false,
      infoData:{},
      dataopen:false,
      selectData:{},
    }
  },
  created () {
    
  },
  methods: {
    moment,
    getSelectData(params = {}) {
        var _this = this
        getUrl('cutDictionary/getAllSelect', params)
          .then(res => {
            console.log(res)
            _this.selectData = res.result
          })
    },
    add () {
      this.getSelectData();
      this.title = '添加'
      this.visible = true
      this.infoData = {companyId:'new_'+this.getUUID(),deptname:''}
    },
    edit (record) {
      this.getSelectData();
      this.title = '编辑'
      this.visible = true
      var _this = this
      this.infoData = {}
      _this.confirmLoading = true
      var params = {companyId:record.companyId}
      getUrl('graduationCompany/getInfo', params)
        .then(res => {
          console.log(res)
           _this.infoData = res.result
          _this.confirmLoading = false
        })
    },
    handleOk(){
      var _this = this
      var params = this.infoData
      var check = this.checkParams(params)
      if(check.flg){
        _this.$message.warning(check.msg)
        return
      }
       console.log(_this.selectData['001']);
      _this.selectData['001'].forEach(element => {
        if(element.code==params.majorcode){
          params['majorname']=element.name
        }
      });
      _this.confirmLoading = true
      postAxiosUrl('graduationCompany/save', params)
      .then(res => {
        if(res.success){
          _this.confirmLoading = false
          _this.$emit('ok', params)
          _this.visible = false
        }else{
          _this.confirmLoading = false
          _this.$message.warning(res.error)
          return
        }
      })
    },
    //{companyId:'new_'+this.getUUID(),companyName:'',companyName:''}
    checkParams(params){
      if(!params.deptname){
        var check = {flg:true,msg:'请输入单位名称'}
        return check
      }
      var check = {flg:false,msg:''}
      return check
    },
    handleCancel () {
      this.visible = false
    },
  }
}
</script>
<style>
    .ant-table-body {
      overflow: auto;
    }
    .ant-modal{
      top:10px
    }
</style>
